home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / crossSection.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.7 KB  |  134 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. proc int getWorldSpaceBoundingBox( 
  18.     string $surfaceShape, float $min[], float $max[], 
  19.     float $center[], float $dimensions[] )
  20. {
  21.     string $surfaceSh = `createNode nurbsSurface`;
  22.     string $surfaceCopy = `createNode transform`;
  23.     string $xformNode = `createNode transformGeometry`;
  24.     parent $surfaceSh $surfaceCopy;
  25.     connectAttr ($surfaceShape + ".local") ($xformNode + ".inputGeometry");
  26.     connectAttr ($surfaceShape + ".worldMatrix") ($xformNode + ".transform");
  27.     connectAttr ($xformNode + ".outputGeometry") ($surfaceSh + ".create");
  28.  
  29.     $min = `getAttr ($surfaceCopy + ".boundingBoxMin")`;
  30.     $max = `getAttr ($surfaceCopy + ".boundingBoxMax")`;
  31.     $dimensions = `getAttr ($surfaceCopy + ".boundingBoxSize")`;
  32.     $center = `getAttr ($surfaceCopy + ".center")`;
  33.     delete $surfaceCopy;
  34.  
  35.     return 0;
  36. }
  37.  
  38. global proc string[] crossSection( string $surface, int $axis, 
  39.     float $spacing, float $offset )
  40. //
  41. //    Description:
  42. //        Given a surface, this proc produces cross sections with the
  43. //        given spacing along the specified axis.  
  44. //        The resulting cross sections are 3D NURBS curves.
  45. //        Offset is how far from the edge of the bounding box to start intersecting.
  46. //        The axis should be given as 0, 1 or 2, for x, y, z respectively.
  47. //
  48. //    Method: 
  49. //        A series of 1x1 degree NURBS planes are created, and intersected
  50. //        with the given surface.
  51. //
  52. //    Returns:
  53. //        A string array, where the first string is the name ofthe group of
  54. //        resulting intersect curves.
  55. //
  56. //    Example:
  57. //        To create cross sections on a surface in the Y direction,
  58. //        where the sections are 2.2 units apart and offset by 1.5 units:
  59. //            crossSection( "surface1", 1, 2.2, 1.5 );
  60. //
  61. {
  62.     string $results[];
  63.  
  64.     // Check that the axis is valid.    
  65.     //
  66.     if( $axis != 0 && $axis != 1 && $axis != 2 )  {
  67.         error("You must specify axis 0, 1 or 2 for x, y, z\n");
  68.         return $results;
  69.     }
  70.     if( size(`ls $surface`) != 1 ) {
  71.         error(" You must specify the name of a surface\n");
  72.         return $results;
  73.     }
  74.     string $surfaceShape[] = `listRelatives -shapes $surface`;
  75.     if( size($surfaceShape) != 1 ) {
  76.         error(" You must specify a transform above a single NURBS surface\n");
  77.         return $results;
  78.     }
  79.  
  80.     string $planes[];
  81.     string $intersectCrvs[];
  82.     string $intersectDNs[];
  83.  
  84.     // Get the bounding box from the surface, incorporate the spacing + offset
  85.     //
  86.     float $bboxMin[3];
  87.     float $bboxMax[3];
  88.     float $bboxSize[3];
  89.     float $bboxCen[3];
  90.     int $tmp = getWorldSpaceBoundingBox( $surfaceShape[0], $bboxMin, 
  91.                 $bboxMax, $bboxCen, $bboxSize );
  92.     float $min = $bboxMin[$axis];
  93.     float $max = $bboxMax[$axis];
  94.     int $ax[3];
  95.     $ax[0] = ($axis == 0) ? 1 : 0;
  96.     $ax[1] = ($axis == 1) ? 1 : 0;
  97.     $ax[2] = ($axis == 2) ? 1 : 0;
  98.     float $pos[3];
  99.     $pos[0] = ($axis == 0) ? $bboxMin[0] + $offset: $bboxCen[0];
  100.     $pos[1] = ($axis == 1) ? $bboxMin[1] + $offset: $bboxCen[1];
  101.     $pos[2] = ($axis == 2) ? $bboxMin[2] + $offset: $bboxCen[2];
  102.  
  103.     float $width = ($axis==0) ? $bboxSize[2] : 
  104.                     (($axis==1) ? $bboxSize[0] : $bboxSize[0]) ;
  105.     float $lr = ($axis==0) ? $bboxSize[1]/$bboxSize[2] : 
  106.                 (($axis==1) ? $bboxSize[2]/$bboxSize[0] : 
  107.                 $bboxSize[1]/$bboxSize[0]) ;
  108.  
  109.     // Create nurbs planes in the specified direction, between min and max,
  110.     // intersect with the surface.  
  111.     //
  112.     for( ; $pos[$axis] < $max; ) {
  113.  
  114.         string $plane[] = `nurbsPlane -d 1 -ch off -ax $ax[0] $ax[1] $ax[2] 
  115.             -p $pos[0] $pos[1] $pos[2] -w $width -lr $lr`;
  116.         $planes[size($planes)] = $plane[0];
  117.  
  118.         string $intersect[] = `intersect -ch on -cos off $plane[0] $surface`;
  119.         $intersectCrvs[size($intersectCrvs)] = $intersect[0];
  120.  
  121.         $pos[0] += ($axis == 0) ? $spacing : 0.0;
  122.         $pos[1] += ($axis == 1) ? $spacing : 0.0;
  123.         $pos[2] += ($axis == 2) ? $spacing : 0.0;
  124.     }
  125.  
  126.     // delete the intersecting planes and group the result curves.
  127.     //
  128.     delete $planes;
  129.     string $intersectCrvsGrp = `group $intersectCrvs`;
  130.     $results[0] = $intersectCrvsGrp;
  131.  
  132.     return $results;
  133. }
  134.